package com.ldl.exam.controller;

import com.ldl.exam.exception.ExamException;
import com.ldl.exam.util.AjaxResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author liudaolin
 * @version 1.0
 * @date 2022/10/04 15:45:30
 */
@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {
    @ResponseBody
    @ExceptionHandler(ExamException.class)
    public AjaxResult examExceptionHandler(ExamException e) {
        log.debug(e.getMessage(), e);
        return AjaxResult.isFail(e.getMessage());
    }

    @ResponseBody
    @ExceptionHandler(Exception.class)
    public AjaxResult globalHandler(Exception e) {
        log.error(e.getMessage(), e);
        return AjaxResult.isFail("服务器繁忙！请稍后重试！");
    }
}
